package com.example.utils;

import com.example.entity.delay.CallCdr;
import com.example.service.IDelayService;
import com.example.utils.redistemplate.RedisTemplateUtils;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ChenXiaoBin
 * on 2019-06-25
 */
public class TestOrder implements Runnable {

    private RedissonClient redissonClient;

    private RedisTemplateUtils redisTemplateUtils;

    public TestOrder (RedissonClient redissonClient, RedisTemplateUtils redisTemplateUtils) {
        this.redissonClient = redissonClient;
        this.redisTemplateUtils = redisTemplateUtils;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        RBlockingQueue<CallCdr> blockingFairQueue = redissonClient.getBlockingQueue("delay_queue");
        RDelayedQueue<CallCdr> delayedQueue = redissonClient.getDelayedQueue(blockingFairQueue);
        while (true){
            System.out.println("111111111111111");
            CallCdr callCdr = null;
            try {
                callCdr = blockingFairQueue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("订单取消时间：" + callCdr.getName() +new SimpleDateFormat("hh:mm:ss").format(new Date())+"==订单生成时间"+callCdr.getPutTime());

        }

    }

}
